<!DOCTYPE html>
<html lang="zh-CN">
<head>

<#include "bases/global_style.ftl"> 
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">


<script>
	var curent_page=${currentpage};
	var curent_page1=${currentpage1};

	var editpformv,editcformv;
	jQuery(document).ready(function()
	{
		var optInit = getOptionsFromForm();
		$("#Pagination").pagination(${totalRecord}, optInit);
		var optInit1 = getOptionsForm();
		$("#Pagination1").pagination(${totalRecord1}, optInit1);
		App.init();
		combox("editProvince","Province",null,null,false);

		editpformv=$("#editPForm").validate({
            debug:false //只验证不提交表单
        });
        editcformv=$("#editCForm").validate({
            debug:false //只验证不提交表单
        });
        
	});

	function getOptionsForm()
	{
		var opt = {callback: pageselectCallback1};
		opt['items_per_page'] = 15;
		opt['num_display_entries'] = 10;
		opt['num'] = 2;
		opt['prev_text'] = '上一页';
		opt['next_text'] = '下一页';
		opt['current_page'] = curent_page;
		return opt;
	}

	function pageselectCallback(page_index, jq)
    {
        if (curent_page != page_index)
        {
            $("#currentpage").val(page_index);
            $("#privateform").submit();
            return true;
        }
    }

	function pageselectCallback1(page_index, jq)
    {
        if (curent_page1 != page_index)
        {
            $("#currentpage1").val(page_index);
            $("#companyform").submit();
            return true;
        }
    }

	//银行账号验证
   	function check_bank(account,id)
   	{
	   	var reg = /^(\d{4}[\s\-]?){4,5}\d{3}$/g;
		if(!reg.test(account)){
			$("#"+id).append("<span id='acc' for='addBankNum' class='error' style='display: inline;'>请输入正确银行账号</span>");
		}else{
			$("#acc").remove();
		}
	}
	//身份证验证
	function check_id(idcard,id)
   	{
	   	var reg = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
		if(!reg.test(idcard)){
			$("#"+id).append("<span id='idcard' for='addIdentity' class='error' style='display: inline;'>请输入正确身份证号</span>");
		}else{
			$("#idcard").remove();
		}
	}

	function showPrivate(id)
	{
		$.ajax({
			type : "POST",
    		url : CONTEXT+'/get_accountuser_by_id?id='+id,
    		dataType : "json",  
  	        cache : false,  
  	        async : false,
  	      	success : function(data) {
  	      		var url="${base}/checkNameUnique?category=AccountUserName&where=and del=0 and id<>"+data.id;
  	      		$("#editPDiv #editPId").val(data.id);
  	      		$("#editPDiv #editPAccount").text(data.account);
  	      		$("#editPDiv #editPType").text("个人");
  	      		$("#editPDiv #editPName").val(data.name);
  	      		$("#editPDiv #editPName").attr("data-rule-remote",url);
  	      		$("#editPDiv #editPTel").val(data.tel);
  	      		$("#editPDiv #editPIdentity").val(data.identityid);
  	      		$("#editPDiv #editPCarbrand").val(data.carbrand);
  	      		$("#editPDiv #editPCartype option[value='"+data.cartypeid+"']").attr("selected", true);
  	      		$("#editPDiv #editProvince option[value='"+data.provinceid+"']").attr("selected", true);  
	        	$("#editPDiv #editProvince").trigger("change");
	        	$("#editPDiv #editCity option[value='"+data.cityid+"']").attr("selected", true);
	        	showPopup("editPDiv");
  	      	}
		});
	}

	function showCompany(id)
	{
		$.ajax({
			type : "POST",
    		url : CONTEXT+'/get_accountuser_by_id?id='+id,
    		dataType : "json",  
  	        cache : false,  
  	        async : false,
  	      	success : function(data) {
  	      		var url2="${base}/checkNameUnique?category=AccountUserName&where=and del=0 and id<>"+data.id;
      	    	$("#editCDiv #editCId").val(data.id);
      	    	$("#editCDiv #editCAccount").text(data.account);
      	    	$("#editCDiv #editCType").text("公司");
      	    	$("#editCDiv #editCName").val(data.name);
      	  		$("#editCDiv #editCName").attr("data-rule-remote",url2);
      	    	$("#editCDiv #editCtel").val(data.tel);
      	    	$("#editCDiv #editBankNum").val(data.bank_num);
      	    	$("#editCDiv #editBankAcc").val(data.bank_account);
      	    	$("#editCDiv #editComment").val(data.comment);
      	    	showPopup("editCDiv");
  	      	}
		});
	}

	function updatePTable()
	{
		editpformv.form();
   		if(editpformv.valid()){
   			$("#editPForm").submit();
	   	}
		
	}

	function updateCTable()
	{
		editcformv.form();
   		if(editcformv.valid()){
			$("#editCForm").submit();
   		}
	}

	function showPopup(div) 
    {//弹出层
        var backDiv = document.getElementById("backDiv");
        backDiv.style.top = "0%";//设置弹出层距离上边界的距离
        backDiv.style.left = "0%";//设置弹出层距离左边界的距离
        backDiv.style.width = "100%";//设置弹出层的宽度
        backDiv.style.height = "100%";//设置弹出层的高度
        backDiv.style.visibility = "visible";

        var addDiv = document.getElementById(div);
        addDiv.style.top = "10%";//设置弹出层距离上边界的距离
        addDiv.style.left = "30%";//设置弹出层距离左边界的距离
        addDiv.style.width = "40%";//设置弹出层的宽度
        addDiv.style.height = "auto";//设置弹出层的高度
        addDiv.style.visibility = "visible";

    }

	function hidePopup() 
    {//关闭层

        // resetLabel();
        var backDiv = document.getElementById("backDiv");
        backDiv.style.visibility = "hidden";

        var editPDiv = document.getElementById("editPDiv");
        editPDiv.style.visibility = "hidden";

        var editCDiv = document.getElementById("editCDiv");
        editCDiv.style.visibility = "hidden";
    }

	function allDivHide() 
    {
        hidePopup();
    }

    function Private()
    {
    	$("#privateDiv").css("display","block");
		$("#companyDiv").css("display","none");
		$("#Private").addClass("page-now list-headBtn");
		$("#Company").removeClass("page-now list-headBtn");
		$("#Private").attr("onclick","");
		$("#Company").attr("onclick","Company()");
    }

    function Company()
    {
    	$("#privateDiv").css("display","none");
		$("#companyDiv").css("display","block");
		$("#Company").addClass("page-now list-headBtn");
		$("#Private").removeClass("page-now list-headBtn");
		$("#Company").attr("onclick","");
		$("#Private").attr("onclick","Private()");
    }

    function doDownloadPExcel()
    {
    	$("#privateform").attr("action","<@spring.url '/download_account_record'></@spring.url>");
    	$("#privateform").submit();
    }

    function doDownloadCExcel()
    {
    	$("#companyform").attr("action","<@spring.url '/download_account_record'></@spring.url>");
    	$("#companyform").submit();
    }
</script>
</head>

<body>

	<div id="backDiv" onclick="allDivHide()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>

	<!-- 编辑个人账号 -->
	<div id="editPDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
		<div class="span12">
        <div class="portlet box green" style="margin: -1px;">
            <div class="portlet-title">
                <div class="caption"><i class="icon-edit"></i>编辑信息</div>
                <a href="javascript:hideEditTable();" class="remove"></a>
            </div>
            
            <div class="portlet-body flip-scroll">
            	<form id="editPForm" action="<@spring.url '/edit_private_account_user'></@spring.url>" method="POST">
            	<table class="table-bordered table-striped table-condensed flip-content">
            		<tbody role="alert" aria-live="polite" aria-relevant="all">
            		<input type="hidden" id="editPId" name="id"/>
            		<tr class="even">
            			<td style="text-align: right;">账号</td>
            			<td class="even">
            				<span id="editPAccount"></span>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">账户类型</td>
            			<td class="even">
            				<span id="editPType"></span>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">所属个人<span class="fill-must">*</span></td>
            			<td class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editPName" name="name" placeholder="请输入姓名" required data-rule-remote="" data-msg-remote="姓名已存在"/>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">手机号<span class="fill-must">*</span></td>
            			<td class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editPTel" name="tel" placeholder="请输入手机号" required data-rule-mobile="true" data-msg-mobile="请输入正确格式"/>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">身份证号</td>
            			<td id="checkeditid" class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editPIdentity" name="identityid" placeholder="请输入身份证号" onblur="check_id($(this).val(),'checkeditid')"/>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">车牌号<span class="fill-must">*</span></td>
            			<td id="checkeditcar" class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editPCarbrand" name="carbrand" placeholder="请输入车牌号" required readonly="true" onblur="check_car($(this).val(),'checkeditcar')"/>
            			</td>
            		</tr>
            		<tr class="even">
                		<td style="text-align: right;">车型<span class="fill-must">*</span></td>
                		<td class="even">
                			<select id="editPCartype" name="cartype" class="m-wrap span8" style="margin-top: 10px" placeholder="" required disabled="disabled">
                				<option value="">===请选择===</option>
									<#if cartypeList?exists>
										<#list cartypeList as ctlist>
											<option value="${ctlist.getKey()}"><#if ctlist.getName()?exists>${ctlist.getName()}</#if></option>
										</#list>
									</#if>
                			</select>
                		</td>
                	</tr>
                	<tr class="even">
                		<td style="text-align: right;">所在地区<span class="fill-must">*</span></td>
                		<td class="even">
                			<select id="editProvince" name="provinceid" class="m-wrap span8" onchange="combox('editCity','City',$(this).val(),null,false)" required style="margin-top: 10px">
                			</select>
                			<select id="editCity" name="cityid" class="m-wrap span8" style="margin-top: 10px" required>
                			</select>
                		</td>
                	</tr>
            		</tbody>
            		</table>
            		<div class="controls controls-row" style="text-align: right;">
                        <input type="button" value="保存" class="btn green" onclick="updatePTable()"/>
                        <input type="button" value="取消" class="btn green" onclick="allDivHide()" />
                    </div>
            	</form>
            </div>
        </div>
        </div>
	</div>
	
	<!-- 编辑公司账号 -->
	<div id="editCDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
		<div class="span12">
        <div class="portlet box green" style="margin: -1px;">
            <div class="portlet-title">
                <div class="caption"><i class="icon-edit"></i>编辑信息</div>
                <a href="javascript:hideEditTable();" class="remove"></a>
            </div>
            
            <div class="portlet-body flip-scroll">
            	<form id="editCForm" action="<@spring.url '/edit_company_account_user'></@spring.url>" method="POST">
            	<table class="table-bordered table-striped table-condensed flip-content">
            		<tbody role="alert" aria-live="polite" aria-relevant="all">
            		<input   type="hidden" id="editCId" name="id" />
            		<tr class="even">
            			<td style="text-align: right;">账号</td>
            			<td class="even">
            				<span id="editCAccount"></span>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">账户类型</td>
            			<td class="even">
            				<span id="editCType"></span>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">公司名称<span class="fill-must">*</span></td>
            			<td class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editCName" name="name" placeholder="请输入公司名称" required data-rule-remote="" data-msg-remote="公司名称已存在"/>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">接收短信手机<span class="fill-must">*</span></td>
            			<td class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editCtel" name="tel" placeholder="请输入接收短信手机" required data-rule-mobile="true" data-msg-mobile="请输入正确格式" />
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">银行账号<span class="fill-must">*</span></td>
            			<td id="checkeditbank" class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editBankNum" name="bankNum" placeholder="请输入银行账号" required onblur="check_bank($(this).val(),'checkeditbank')"/>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">开户行<span class="fill-must">*</span></td>
            			<td class="even">
            				<input class="m-wrap span8" style="margin-top: 10px" type="text" id="editBankAcc" name="bankAccount" placeholder="请输入开户行" required/>
            			</td>
            		</tr>
            		<tr class="even">
            			<td style="text-align: right;">说明</td>
                        <td class="even">
                            <textarea class="form-control" rows="3" id="editComment" name="comment" placeholder=""></textarea>
                        </td>
            		</tr>
            		</tbody>
            		</table>
            		<div class="controls controls-row" style="text-align: right;">
                        <input type="button" value="保存" class="btn green" onclick="updateCTable()"/>
                        <input type="button" value="取消" class="btn green" onclick="allDivHide()" />
                    </div>
            	</form>
            </div>
        </div>
        </div>
	</div>
<#include "bases/navhead.ftl"> 
<#include "bases/sidebar.ftl">

	<div class="page-container secMenu-content">

		<div class="page-content">

			<div class="container-fluid">

				<div class="row-fluid">
					<div class="span12">
						<div class="portlet box green">
							<div class="portlet-title">
								<div class="caption">
									<i class="fa fa-cogs"></i>账户记录
								</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
							</div>
							
							<div class="portlet-body flip-scroll">
								<a id="Private" class="btn page-role <#if (type!'')=='1'><#else>page-now list-headBtn</#if>" <#if (type!'')=='1'>onclick="Private()"<#else>onclick=""</#if>>个人类型账户</a>
	  							<a id="Company" class="btn page-role <#if (type!'')=='1'>page-now list-headBtn<#else></#if>" <#if (type!'')=='1'>onclick=""<#else>onclick="Company()"</#if>>公司类型账户</a>
							</div>

							<!-- 个人账户 -->
							<div id="privateDiv" class="portlet-body flip-scroll" <#if (type!'')=='1'>style="display:none"<#else></#if>>
								<form id="privateform" action="<@spring.url '/account_record_manage'></@spring.url>" method="POST">
									<input type="hidden" id="currentpage" name="page" value="0" />
									<input type="hidden" id="pexport" name="export" value="0" />
									<input type="hidden" id="postactionorder1" name="postactionorder1" />

									<div class="controls controls-row">

										<input type="text" name="tel" class="form-control sheet-searchInput" value="<#if tel?exists>${tel}</#if>" placeholder="输入手机号">
										<input type="text" name="Paccount" class="form-control sheet-searchInput" value="<#if Paccount?exists>${Paccount}</#if>" placeholder="输入账号">

										<button type="submit" class="btn blue">搜索</button>
									</div>
									
									<div class="controls controls-row" style="margin-top: 20px">
										<button type="button" class="btn green" onclick="doDownloadPExcel()">导出</button>
									</div>

									<table class="table table-bordered table-hover table-striped table-condensed list-table">
										<thead class="flip-content">
											<tr>
												<th><input type="checkbox" class="checkbox-length list-checkboxAll"></th>
												<th style="text-align: center;">账号</th>
												<th style="text-align: center;">所属个人</th>
												<th style="text-align: center;">可用余额</th>
												<th style="text-align: center;">返现余额</th>
												<th style="text-align: center;">累计返现</th>
												<th style="text-align: center;">累计消费</th>
												<th style="text-align: center;">累计充值</th>
												<th style="text-align: center;">累计退款</th>
												<th style="text-align: center;">有效优惠券</th>
											</tr>
										</thead>
										<tbody>
											<#list account_info_p as aip>
											<tr>
												<#if aip?exists>
												<th><input value="${aip.getAccountid()}" name="checklist" type="checkbox" class="list-checkbox"></th>
												<td style="text-align: center;"><#if aip.getAccount()?exists>${aip.getAccount()}</#if></td>
												<td style="text-align: center;"><#if aip.getName()?exists>${aip.getName()}</#if></td>
												<td style="text-align: center;"><#if aip.getAvailable_balance()?exists>${aip.getAvailable_balance()/100}</#if></td>
												<td style="text-align: center;">0</td>
												<td style="text-align: center;"><#if aip.getTotal_back_balance()?exists>${aip.getTotal_back_balance()/100}</#if></td>
												<td style="text-align: center;"><#if aip.getTotal_consum()?exists>${aip.getTotal_consum()/100}</#if></td>
												<td style="text-align: center;"><#if aip.getTotal_recharge()?exists>${aip.getTotal_recharge()/100}</#if></td>
												<td style="text-align: center;"><#if aip.getTotal_refund()?exists>${aip.getTotal_refund()/100}</#if></td>
												<td style="text-align: center;"><#if aip.getCoupon_num()?exists>${aip.getCoupon_num()}</#if></td>
												</#if>
											</tr>
											</#list>
										</tbody>
									</table>
									<div class="controls controls-row">
										<div id="Pagination" class="pagination"></div>
									</div>
								</form>
							</div>
							
							<!-- 公司账户 -->
							<div id="companyDiv" class="portlet-body flip-scroll" <#if (type!'')=='1'>style="display:block"<#else>style="display:none;"</#if>>
								<form id="companyform" action="<@spring.url '/account_record_manage?type=1'></@spring.url>" method="POST">
									<input type="hidden" id="currentpage1" name="page1" value="0" />
									<input type="hidden" id="cexport" name="export" value="1" />
									<input type="hidden" id="postactionorder1" name="postactionorder1" />

									<div class="controls controls-row">

										<input type="text" name="Caccount" class="form-control sheet-searchInput" value="<#if Caccount?exists>${Caccount}</#if>" placeholder="输入账号">
										<select  name="accountid"  class="form-control sheet-searchInput" value="${accountid!}">
											<option value="">选择所属公司</option>
				  							<#if companyList??>
	                                			<#list companyList as clist> 
	                                    			<option value="${clist.getKey()}" <#if (accountid!'')=="${clist.getKey()}">selected="selected"</#if>><#if clist.getName()??>${clist.getName()}</#if></option>
	                                			</#list>
                                  			</#if>
										</select>

										<button type="submit" class="btn blue" onclick="">搜索</button>
									</div>
									
									<div class="controls controls-row" style="margin-top: 20px">
										<button type="button" class="btn green" onclick="doDownloadCExcel()">导出</button>
									</div>

									<table class="table table-bordered table-hover table-striped table-condensed list-table">
										<thead class="flip-content">
											<tr>
												<th><input type="checkbox" class="checkbox-length list-checkboxAll"></th>
												<th style="text-align: center;">账号</th>
												<th style="text-align: center;">所属公司</th>
												<th style="text-align: center;">说明</th>
												<th style="text-align: center;">可用余额</th>
												<th style="text-align: center;">累计免费里程</th>
												<th style="text-align: center;">累计消费</th>
												<th style="text-align: center;">累计充值</th>
												<th style="text-align: center;">累计退款</th>
											</tr>
										</thead>
										<tbody>
											<#list account_info_c as aic>
											<tr>
												<#if aic?exists>
												<th><input value="${aic.getAccountid()}" name="checklist" type="checkbox" class="list-checkbox"></th>
												<td style="text-align: center;"><#if aic.getAccount()?exists>${aic.getAccount()}</#if></td>
												<td style="text-align: center;"><#if aic.getName()?exists>${aic.getName()}</#if></td>
												<td style="text-align: center;"><#if aic.getComment()?exists>${aic.getComment()}</#if></td>
												<td style="text-align: center;"><#if aic.getAvailable_balance()?exists>${aic.getAvailable_balance()/100}</#if></td>
												<td style="text-align: center;"><#if aic.getTotal_free_trace()?exists>${aic.getTotal_free_trace()/1000}</#if></td>
												<td style="text-align: center;"><#if aic.getTotal_consum()?exists>${aic.getTotal_consum()/100}</#if></td>
												<td style="text-align: center;"><#if aic.getTotal_recharge()?exists>${aic.getTotal_recharge()/100}</#if></td>
												<td style="text-align: center;"><#if aic.getTotal_refund()?exists>${aic.getTotal_refund()/100}</#if></td>
												</#if>
											</tr>
											</#list>
										</tbody>
									</table>
									<div class="controls controls-row">
										<div id="Pagination1" class="pagination"></div>
									</div>
								</form>
							</div>
							
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>